<?php
	session_start();
	if(!isset($_SESSION["jara_admin"])) {
		header("Location: ../login.php");
		exit;
	}
	if($_SESSION["jara_permissions"][2] == 0) {	
		header("Location: error.php");
		exit;
	}
	require_once("../include/templating_fns.php");
	require_once("../include/db_fns.php");
	jara_page_start("Delete User - Administrator CP");
	try {
		$id = $_REQUEST["id"];
		if($id == 1) {
			throw new JaraGeneralException("You cannot the delete the superuser.");
		}
		$query = "delete from jara_users where id = '$id'";
		$result = jara_db_query($query);
		if($result == 0) {
			throw new JaraGeneralException("Could not delete the user from the database.");
		}
		else {
			echo "<p>Successfully deleted the user with ID <strong>$id</strong>.</p>";
		}
	}
	catch(JaraDatabaseException $ex) {
?>
	<p>
		A database error occured during the process of creating this page.
	</p>
	<p>
		Error type: <?php echo (($ex->getSqlStage() == 1) ? "MySQL connection error" : "MySQL query error"); ?><br />
		Error message: &quot;<?php echo $ex->getSqlMsg(); ?>&quot; [code <?php echo $ex->getSqlCode(); ?>]
	</p>
<?php
		jara_page_end();
		exit;
	}
	catch(JaraGeneralException $ex) {
?>
	<p>
		A general error occured during the process of creating this page.
	</p>
	<p>
		Error message: &quot;<?php echo $ex->getMessage(); ?>&quot;
	</p>
<?php
		jara_page_end();
		exit;
	}
	jara_page_end();
?>